﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi
{
    /// <summary>
    /// 设置数据表的备注
    /// </summary>
    [CPPEI.WebApi.AuthPostAction("DataTable", "UpdateDescription", "1.0")]
    public class UpdateDescriptionAction : BaseAction<UpdateDescriptionParams, UpdateDescriptionResult>
    {
        protected override ActionResult<UpdateDescriptionResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            UpdateDescriptionParams opParams)
        {
            SER.DtTableService service = new SER.DtTableService();
            ServiceResult serResult = service.UpdateDescription(opParams.DataTableId, opParams.Description);

            if(serResult.IsSuccess)
            {
                UpdateDescriptionResult result = new UpdateDescriptionResult();

                return new ActionResult<UpdateDescriptionResult>(result);
            }
            else
            {
                return new ActionResult<UpdateDescriptionResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class UpdateDescriptionParams
    {
        [Parameter]
        public Guid DataTableId { get; set; }

        [Parameter]
        public string Description { get; set; }
    }

    public class UpdateDescriptionResult
    {
    }
}
